/**
 * <copyright>
 * </copyright>
 *

 */
package org.xtext.example.cr.cR.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.xtext.example.cr.cR.Add;
import org.xtext.example.cr.cR.Archive;
import org.xtext.example.cr.cR.Array;
import org.xtext.example.cr.cR.ArrayElement;
import org.xtext.example.cr.cR.CRPackage;
import org.xtext.example.cr.cR.CalcCR;
import org.xtext.example.cr.cR.CalcMean;
import org.xtext.example.cr.cR.Size;
import org.xtext.example.cr.cR.Variable;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Add</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getArray <em>Array</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getArrayElement <em>Array Element</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getMethod <em>Method</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getNumParams <em>Num Params</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getVarParams <em>Var Params</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getAeParams <em>Ae Params</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getArchive <em>Archive</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getSizes <em>Sizes</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getCalcCRs <em>Calc CRs</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.AddImpl#getCalcMeans <em>Calc Means</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class AddImpl extends MinimalEObjectImpl.Container implements Add
{
  /**
   * The cached value of the '{@link #getArray() <em>Array</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getArray()
   * @generated
   * @ordered
   */
  protected Array array;

  /**
   * The cached value of the '{@link #getArrayElement() <em>Array Element</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getArrayElement()
   * @generated
   * @ordered
   */
  protected ArrayElement arrayElement;

  /**
   * The default value of the '{@link #getMethod() <em>Method</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMethod()
   * @generated
   * @ordered
   */
  protected static final String METHOD_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getMethod() <em>Method</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMethod()
   * @generated
   * @ordered
   */
  protected String method = METHOD_EDEFAULT;

  /**
   * The cached value of the '{@link #getNumParams() <em>Num Params</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getNumParams()
   * @generated
   * @ordered
   */
  protected EList<org.xtext.example.cr.cR.Number> numParams;

  /**
   * The cached value of the '{@link #getVarParams() <em>Var Params</em>}' reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getVarParams()
   * @generated
   * @ordered
   */
  protected EList<Variable> varParams;

  /**
   * The cached value of the '{@link #getAeParams() <em>Ae Params</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getAeParams()
   * @generated
   * @ordered
   */
  protected EList<ArrayElement> aeParams;

  /**
   * The cached value of the '{@link #getArchive() <em>Archive</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getArchive()
   * @generated
   * @ordered
   */
  protected EList<Archive> archive;

  /**
   * The cached value of the '{@link #getSizes() <em>Sizes</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getSizes()
   * @generated
   * @ordered
   */
  protected EList<Size> sizes;

  /**
   * The cached value of the '{@link #getCalcCRs() <em>Calc CRs</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getCalcCRs()
   * @generated
   * @ordered
   */
  protected EList<CalcCR> calcCRs;

  /**
   * The cached value of the '{@link #getCalcMeans() <em>Calc Means</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getCalcMeans()
   * @generated
   * @ordered
   */
  protected EList<CalcMean> calcMeans;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected AddImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return CRPackage.Literals.ADD;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Array getArray()
  {
    if (array != null && array.eIsProxy())
    {
      InternalEObject oldArray = (InternalEObject)array;
      array = (Array)eResolveProxy(oldArray);
      if (array != oldArray)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, CRPackage.ADD__ARRAY, oldArray, array));
      }
    }
    return array;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Array basicGetArray()
  {
    return array;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setArray(Array newArray)
  {
    Array oldArray = array;
    array = newArray;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.ADD__ARRAY, oldArray, array));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ArrayElement getArrayElement()
  {
    return arrayElement;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetArrayElement(ArrayElement newArrayElement, NotificationChain msgs)
  {
    ArrayElement oldArrayElement = arrayElement;
    arrayElement = newArrayElement;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CRPackage.ADD__ARRAY_ELEMENT, oldArrayElement, newArrayElement);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setArrayElement(ArrayElement newArrayElement)
  {
    if (newArrayElement != arrayElement)
    {
      NotificationChain msgs = null;
      if (arrayElement != null)
        msgs = ((InternalEObject)arrayElement).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CRPackage.ADD__ARRAY_ELEMENT, null, msgs);
      if (newArrayElement != null)
        msgs = ((InternalEObject)newArrayElement).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CRPackage.ADD__ARRAY_ELEMENT, null, msgs);
      msgs = basicSetArrayElement(newArrayElement, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.ADD__ARRAY_ELEMENT, newArrayElement, newArrayElement));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getMethod()
  {
    return method;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMethod(String newMethod)
  {
    String oldMethod = method;
    method = newMethod;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.ADD__METHOD, oldMethod, method));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<org.xtext.example.cr.cR.Number> getNumParams()
  {
    if (numParams == null)
    {
      numParams = new EObjectContainmentEList<org.xtext.example.cr.cR.Number>(org.xtext.example.cr.cR.Number.class, this, CRPackage.ADD__NUM_PARAMS);
    }
    return numParams;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Variable> getVarParams()
  {
    if (varParams == null)
    {
      varParams = new EObjectResolvingEList<Variable>(Variable.class, this, CRPackage.ADD__VAR_PARAMS);
    }
    return varParams;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<ArrayElement> getAeParams()
  {
    if (aeParams == null)
    {
      aeParams = new EObjectContainmentEList<ArrayElement>(ArrayElement.class, this, CRPackage.ADD__AE_PARAMS);
    }
    return aeParams;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Archive> getArchive()
  {
    if (archive == null)
    {
      archive = new EObjectContainmentEList<Archive>(Archive.class, this, CRPackage.ADD__ARCHIVE);
    }
    return archive;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Size> getSizes()
  {
    if (sizes == null)
    {
      sizes = new EObjectContainmentEList<Size>(Size.class, this, CRPackage.ADD__SIZES);
    }
    return sizes;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<CalcCR> getCalcCRs()
  {
    if (calcCRs == null)
    {
      calcCRs = new EObjectContainmentEList<CalcCR>(CalcCR.class, this, CRPackage.ADD__CALC_CRS);
    }
    return calcCRs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<CalcMean> getCalcMeans()
  {
    if (calcMeans == null)
    {
      calcMeans = new EObjectContainmentEList<CalcMean>(CalcMean.class, this, CRPackage.ADD__CALC_MEANS);
    }
    return calcMeans;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case CRPackage.ADD__ARRAY_ELEMENT:
        return basicSetArrayElement(null, msgs);
      case CRPackage.ADD__NUM_PARAMS:
        return ((InternalEList<?>)getNumParams()).basicRemove(otherEnd, msgs);
      case CRPackage.ADD__AE_PARAMS:
        return ((InternalEList<?>)getAeParams()).basicRemove(otherEnd, msgs);
      case CRPackage.ADD__ARCHIVE:
        return ((InternalEList<?>)getArchive()).basicRemove(otherEnd, msgs);
      case CRPackage.ADD__SIZES:
        return ((InternalEList<?>)getSizes()).basicRemove(otherEnd, msgs);
      case CRPackage.ADD__CALC_CRS:
        return ((InternalEList<?>)getCalcCRs()).basicRemove(otherEnd, msgs);
      case CRPackage.ADD__CALC_MEANS:
        return ((InternalEList<?>)getCalcMeans()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case CRPackage.ADD__ARRAY:
        if (resolve) return getArray();
        return basicGetArray();
      case CRPackage.ADD__ARRAY_ELEMENT:
        return getArrayElement();
      case CRPackage.ADD__METHOD:
        return getMethod();
      case CRPackage.ADD__NUM_PARAMS:
        return getNumParams();
      case CRPackage.ADD__VAR_PARAMS:
        return getVarParams();
      case CRPackage.ADD__AE_PARAMS:
        return getAeParams();
      case CRPackage.ADD__ARCHIVE:
        return getArchive();
      case CRPackage.ADD__SIZES:
        return getSizes();
      case CRPackage.ADD__CALC_CRS:
        return getCalcCRs();
      case CRPackage.ADD__CALC_MEANS:
        return getCalcMeans();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case CRPackage.ADD__ARRAY:
        setArray((Array)newValue);
        return;
      case CRPackage.ADD__ARRAY_ELEMENT:
        setArrayElement((ArrayElement)newValue);
        return;
      case CRPackage.ADD__METHOD:
        setMethod((String)newValue);
        return;
      case CRPackage.ADD__NUM_PARAMS:
        getNumParams().clear();
        getNumParams().addAll((Collection<? extends org.xtext.example.cr.cR.Number>)newValue);
        return;
      case CRPackage.ADD__VAR_PARAMS:
        getVarParams().clear();
        getVarParams().addAll((Collection<? extends Variable>)newValue);
        return;
      case CRPackage.ADD__AE_PARAMS:
        getAeParams().clear();
        getAeParams().addAll((Collection<? extends ArrayElement>)newValue);
        return;
      case CRPackage.ADD__ARCHIVE:
        getArchive().clear();
        getArchive().addAll((Collection<? extends Archive>)newValue);
        return;
      case CRPackage.ADD__SIZES:
        getSizes().clear();
        getSizes().addAll((Collection<? extends Size>)newValue);
        return;
      case CRPackage.ADD__CALC_CRS:
        getCalcCRs().clear();
        getCalcCRs().addAll((Collection<? extends CalcCR>)newValue);
        return;
      case CRPackage.ADD__CALC_MEANS:
        getCalcMeans().clear();
        getCalcMeans().addAll((Collection<? extends CalcMean>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case CRPackage.ADD__ARRAY:
        setArray((Array)null);
        return;
      case CRPackage.ADD__ARRAY_ELEMENT:
        setArrayElement((ArrayElement)null);
        return;
      case CRPackage.ADD__METHOD:
        setMethod(METHOD_EDEFAULT);
        return;
      case CRPackage.ADD__NUM_PARAMS:
        getNumParams().clear();
        return;
      case CRPackage.ADD__VAR_PARAMS:
        getVarParams().clear();
        return;
      case CRPackage.ADD__AE_PARAMS:
        getAeParams().clear();
        return;
      case CRPackage.ADD__ARCHIVE:
        getArchive().clear();
        return;
      case CRPackage.ADD__SIZES:
        getSizes().clear();
        return;
      case CRPackage.ADD__CALC_CRS:
        getCalcCRs().clear();
        return;
      case CRPackage.ADD__CALC_MEANS:
        getCalcMeans().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case CRPackage.ADD__ARRAY:
        return array != null;
      case CRPackage.ADD__ARRAY_ELEMENT:
        return arrayElement != null;
      case CRPackage.ADD__METHOD:
        return METHOD_EDEFAULT == null ? method != null : !METHOD_EDEFAULT.equals(method);
      case CRPackage.ADD__NUM_PARAMS:
        return numParams != null && !numParams.isEmpty();
      case CRPackage.ADD__VAR_PARAMS:
        return varParams != null && !varParams.isEmpty();
      case CRPackage.ADD__AE_PARAMS:
        return aeParams != null && !aeParams.isEmpty();
      case CRPackage.ADD__ARCHIVE:
        return archive != null && !archive.isEmpty();
      case CRPackage.ADD__SIZES:
        return sizes != null && !sizes.isEmpty();
      case CRPackage.ADD__CALC_CRS:
        return calcCRs != null && !calcCRs.isEmpty();
      case CRPackage.ADD__CALC_MEANS:
        return calcMeans != null && !calcMeans.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (method: ");
    result.append(method);
    result.append(')');
    return result.toString();
  }

} //AddImpl
